package day03;

import java.util.Scanner;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/10
 */
public class FibonacciSequence {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入斐波那契数列项数：");
        int num = sc.nextInt();
        int n1=1; // 斐波那契数列第一项
        int n2=1; // 斐波那契数列第二项

        System.out.println("斐波那契数列前"+num+"项如下：");
        for (int i = 1; i <= num; i++) {
            if (i==1){
                System.out.print(n1+" ");
            } else if (i == 2) {
                System.out.print(n2+" ");
            }else {
                int next = n1 + n2;
                System.out.print(next+" ");
                n1 = n2;
                n2 = next;
            }
        }
    }
}
